#ifndef COMPILE_H
#define COMPILE_H

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#define YYERROR_VERBOSE
//#define LEXDEBUG
#define LEXWORK  
#define YYDEBUG 1
#define YYSTYPE parse*
extern int yydebug;
using namespace std;

class parse{
public:
    string token;
    string value;
    int line;
    vector<parse*> children;
    parse(){}
    parse(int line, string token, string value){
        this->line = line;
        this->token = token;
        this->value = value;
    }
    void bfs(void){
        queue<parse*> Q;
        queue<int> q;
        Q.push(this);
        q.push(1);
        int layer1 = 1;
        int layer2 = 0;
        int number = q.front();
        q.pop();
        while(!Q.empty()){
            auto res = Q.front();
            Q.pop();
            cout << res->token;
            layer1 -= 1;
            int t = (int) res->children.size();
            q.push(t);
            layer2 += t;
            for(auto it = res->children.begin(); it != res->children.end(); it++){
                Q.push((*it));
            }
            //cout << "    check " << number << endl;
            if(number <= 1){
                cout << "  ";
                number = q.front();
                q.pop();
            }
            else{
                cout << " ";
                number -= 1;
            }
            while(number == 0 && (!q.empty())){
                cout << "    ";
                number = q.front();
                q.pop();                
            }
            //cout << layer1 << " " << layer2 << endl;
            if(layer1 == 0 && layer2 != 0){
                cout << endl;
                layer1 = layer2;
                layer2 = 0;
            }
        }
        cout << endl;
    }
};

extern parse* syntax_process(const char* file_path);


#endif